package com.niit.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.Question;
import com.niit.service.QuestionService;
import com.niit.service.impl.QuestionServiceImpl;
import com.niit.utils.WebKit;


@WebServlet("/CheckQuestionController")
public class CheckQuestionController extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Question question = WebKit.request2Bean(request, Question.class);
		QuestionService qs = new QuestionServiceImpl();
		if(question.isChecked()==true){
			int a = qs.update(question);
			if(a==0){
				response.getOutputStream().write("审核失败".getBytes());
			}else if(a==1){
				response.getOutputStream().write("审核成功".getBytes());
			}
		}else{
			int a = qs.delete(question);
			if(a==0){
				response.getOutputStream().write("删除失败".getBytes());
			}else if(a==1){
				response.getOutputStream().write("删除成功".getBytes());
			}
			
		}
	}

}
